<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>登录页面</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="/static/layuiadmin/style/login.css" media="all">
</head>
<body>

  <form action="/login" method="POST" class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;" >

    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>学习测试</h2>
        <p>学习测试</p>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" name="username" id="username" lay-verify="required" placeholder="用户名" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
        </div>
      </div>
  	</div>
  </form>
  <script src="/static/layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'user','jquery'], function(){
    var $ = layui.$
    ,setter = layui.setter
    ,admin = layui.admin
    ,form = layui.form
    ,router = layui.router()
    ,search = router.search;
    form.render();
    //提交
    form.on('submit(LAY-user-login-submit)', function(obj){
     	var username =$("#username").val().trim();
     	var password =$("#password").val().trim();
     	if(username==""||password==""){
     		layer.msg('帐号密码不能为空', {
     		      offset: '15px'
     		      ,icon: 1
     		    });
     		return false;
     	}
      $.ajax({
        type: "POST",
        url: "/login",
        data: {"username":username,"password":password},
        dataType: "JSON",
        success: function(result){
          if(result.code == 0){
            let host = window.location.href;
            if(host.indexOf("http://")>-1){
              let url = host.substr(host.indexOf("http://")+7,host.length);
              host = "http://" + url.substr(0,url.indexOf("/")+1);
            }else if(host.indexOf("https://")>-1){
              let url = host.substr(host.indexOf("http://")+8,host.length);
              host = "https://" + url.substr(0,url.indexOf("/")+1);
            }
            window.location.href = host;
          }else{
            layer.msg(result.msg, {
              offset: '15px'
              ,icon: 2
            });
          }
        }
      });
     	return false;
    });
  });
  </script>
</body>
</html>
